Recreate the following plots shown below. Don't worry if your plots don't match exactly what is shown below, as long as you have a general understanding of ggplot2 and the grammar of graphics
Some of the images may be distorted from the conversion to a web format
For the first few plots, use the mpg dataset
library(ggplot2)
library(ggthemes)
head(mpg)
Histogram of hwy mpg values:
ggplot(mpg,aes(x=hwy)) + geom_histogram(bins=20,fill='red',alpha=0.5)
Barplot of car counts per manufacturer with color fill defined by cyl count
ggplot(mpg,aes(x=manufacturer)) + geom_bar(aes(fill=factor(cyl))) + theme_gdocs()
Switch now to use the txhousing dataset that comes with ggplot2
head(txhousing)
Create a scatterplot of volume versus sales. Afterwards play around with alpha and color arguments to clarify information.
pl <- ggplot(txhousing,aes(x=sales,y=volume)) + geom_point(color='blue',alpha=0.5)
print(pl)
Add a smooth fit line to the scatterplot from above. Hint: You may need to look up geom_smooth()
pl + geom_smooth(color='red')
Up next you'll have a data visualization project in which you will build up a real data visualization used in The Economist.